package com.web.kdl.pojo.Vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.web.kdl.entity.flywheelDataAnalysis.FlywheelDataAnalysis;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.text.DecimalFormat;
import java.time.LocalDateTime;

@Data
@NoArgsConstructor
public class FlywheelInfoVo {
    private Integer id;
    private String deviceName;
    private double dataValue; //最新值
    private String unit; //单位
    private String value; //最新值 含数字+单位 （data_value+unit）
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime time; //最新时间
    public FlywheelInfoVo(FlywheelDataAnalysis lastValue){
        this.deviceName=lastValue.getDeviceName();
        if ( lastValue != null && (lastValue.getUnit().equals(null) || lastValue.getUnit().equals("/")) ){
            this.value= String.valueOf(keepTwoDecimalPlaces(lastValue.getDataValue()));
        }else if (lastValue != null){
            this.value=keepTwoDecimalPlaces(lastValue.getDataValue())+ lastValue.getUnit();
        }
    }
    public double keepTwoDecimalPlaces(double value) {
        DecimalFormat df = new DecimalFormat("#.00");
        return Double.parseDouble(df.format(value));
    }
}
